using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Scalextric
{
    public class PB6SendPackage
    {
        public OperationMode OperationMode { get; set; }
        public DriverHandset DrivePacket1 { get; set; }
        public DriverHandset DrivePacket2 { get; set; }
        public DriverHandset DrivePacket3 { get; set; }
        public DriverHandset DrivePacket4 { get; set; }
        public DriverHandset DrivePacket5 { get; set; }
        public DriverHandset DrivePacket6 { get; set; }
        public LEDStatus LEDStatus { get; set; }
        public Checksum Checksum { get; set; }

        public PB6SendPackage(byte[] data)
        {
            if (data.Length != 9)
                throw new Exception();
            OperationMode = new Scalextric.OperationMode(data[0]);
            DrivePacket1 = new DriverHandset(data[1]);
            DrivePacket2 = new DriverHandset(data[2]);
            DrivePacket3 = new DriverHandset(data[3]);
            DrivePacket4 = new DriverHandset(data[4]);
            DrivePacket5 = new DriverHandset(data[5]);
            DrivePacket6 = new DriverHandset(data[6]);
            LEDStatus = new LEDStatus(data[7]);
            Checksum = new Checksum(data);
        }

        public byte[] ExportData()
        {
            byte[] result = new byte[9];
            result[0] = OperationMode.ToByte();
            result[1] = DrivePacket1.ToByte();
            result[2] = DrivePacket2.ToByte();
            result[3] = DrivePacket3.ToByte();
            result[4] = DrivePacket4.ToByte();
            result[5] = DrivePacket5.ToByte();
            result[6] = DrivePacket6.ToByte();
            //convert ready to be sent
            return result;
        }
    }
}
